package com.darksider.basemodule.base.originbase;

import android.arch.lifecycle.ViewModel;
import android.arch.lifecycle.ViewModelProvider;
import android.content.pm.ActivityInfo;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.darksider.basemodule.util.StatusBarUtils;

import javax.inject.Inject;

/**
 * <pre>
 *     author : Darksiderl
 *     e-mail : 1126220529@qq.com
 *     time   : 2017/12/07
 *     desc   : 抽象类将实现延迟到子类中  如获取ContentView
 *              如果只使用 DataBinding, 则 VM 的泛型可以传 {@link ViewModel}
 *     version: 1.0
 * </pre>
 */
public abstract class OriginBaseActivity<DB extends ViewDataBinding, VM extends ViewModel>
        extends AppCompatActivity implements IActivity {

    protected final String TAG = this.getClass().getSimpleName();

    /**
     * ViewDataBinding
     */
    protected DB mBinding;

    /**
     * MVVM ViewModel ViewModelProvider.Factory
     */
    @Inject
    protected ViewModelProvider.Factory mViewModelFactory;
    /**
     * instance in subclass; 自动销毁
     */
    protected VM mViewModel;
    //沉浸式
//    private ImmersionBar mImmersionBar;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (isUseDataBinding()) {
            //设置DataBinding
            mBinding = DataBindingUtil.setContentView(this, getContentView());
        } else {
            setContentView(getContentView());
        }

        //1.StatusBarUtils
        StatusBarUtils.setTransparent(this);
        //2.ImmersionBar
//        ImmersionBar.with(this)
//                .statusBarColor(R.color.md_white)
//                .fitsSystemWindows(true)
//                //使用该属性必须指定状态栏的颜色，不然状态栏透明，很难看
//                .statusBarDarkFont(true, 0.2f)
//                .init();
        //3.先初始化，然后在各个Activity中定制效果
//        mImmersionBar = ImmersionBar.with(this);
//        mImmersionBar.init();
        //在代码中指定竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    }

    /**
     * 默认关闭 Databinding
     * @return
     */
    @Override
    public boolean isUseDataBinding() {
        return false;
    }

}
